package com.mall507.fivepeaks.activity.main;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.hzh.frame.comn.callback.HttpCallBack;
import com.hzh.frame.core.HttpFrame.BaseHttp;
import com.hzh.frame.ui.fragment.AbsRecyclerViewFM;
import com.hzh.frame.widget.xrecyclerview.RecyclerViewHolder;
import com.mall507.comn.model.Original;
import com.mall507.fivepeaks.R;
import com.mall507.fivepeaks.widget.imageview.CircleImageView;
import com.mall507.fivepeaks.widget.imageview.ExpandImageView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 五峰原创
 */
public class MainTownShipJieShaoRFM extends AbsRecyclerViewFM<Original> {
    
    List<String> listUrl;

    public static MainTownShipJieShaoRFM newInstance(int type,String nid) {
        MainTownShipJieShaoRFM myFragment = new MainTownShipJieShaoRFM();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        bundle.putString("nid", nid);
        myFragment.setArguments(bundle);
        return myFragment;
    }

    @Override
    public boolean setTitleIsShow() {
        return false;
    }

    @Override
    protected int setLayoutId() {
        return R.layout.fm_rv_main_township_jieshao;
    }

    @Override
    protected String setHttpPath() {
        return "Township/getTownshipOne";
    }

    @Override
    protected JSONObject setHttpParams() {
        JSONObject params = new JSONObject();
        try {
            params.put("id", getArguments().getString("nid"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return params;
    }
    
    @Override
    protected List<Original> handleHttpData(JSONObject response) {
        List<Original> list = new ArrayList<>();
        if (200 == response.optInt("code")) {
            JSONObject data = response.optJSONObject("data");
            Original model = new Original();
            model.setNid(data.optString("id"));
            model.setTitle(data.optString("township_name"));
            model.setContent(data.optString("township_desc"));
            list.add(model);
        }
        return list;
    }


    @Override
    protected int setItemLayoutId(int viewType) {
        return R.layout.item_rv_main_township_jieshao;
    }

    @Override
    protected void bindItemData(RecyclerViewHolder holder, int position, final Original model) {
        holder.setText(R.id.title,model.getTitle() + "简介");
        holder.setText(R.id.content, "\u3000\u3000" + model.getContent());
    }
}
